
<template>
  <div class="calendar">
    <a
      :href="'#'+monthId"
      hidden />
    <div class="calendar-month">
      <div
        v-for="(days,m) in monthsData"
        :key="(days,m)"
        :id="'monthId'+m"
        class="calendar-month-every">
        <div class="year" ><i class="aiction" @click="changeYear()">{{ year }}<div class="down">&nbsp;</div></i><i>年</i><i class="aiction" @click="changeMonth()">{{ m+1 }}<div class="down">&nbsp;</div></i><i>月</i></div>
        <div class="table-box">
          <table cellpadding="5" >
            <thead>
              <tr>
                <td
                  v-for="week in weeks"
                  :key="week"
                  class="week">{{ week }}</td>
              </tr>
            </thead>
            <tbody>
              <tr
                v-for="(day,k1) in days"
                :key="(day,k1)"
                style="{'animation-delay',(k1*30)+'ms'}">
                <td
                  v-for="(child,k2) in day"
                  :key="(child,k2)"
                  :class="{'selected':child.selected,'disabled':child.disabled}"
                  @click="select(k1,k2,m+1,$event)">
                  <span :class="{'red':k2==0||k2==6||((child.isLunarFestival||child.isGregorianFestival) && lunar)}">{{ child.day }}</span>
                  <div
                    v-if="child.eventName!=undefined"
                    class="text">{{ child.eventName }}</div>
                  <div
                    v-if="lunar"
                    :class="{'isLunarFestival':child.isLunarFestival,'isGregorianFestival':child.isGregorianFestival}"
                    class="text">{{ child.lunar }}</div>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <div
      :class="{'show':yearsShow}"
      class="calendar-years" >
      <span
        v-for="y in years"
        :key="y"
        :class="{'active':y==year}"
        @click.stop="selectYear(y)">{{ y }} 年</span>
    </div>
    <div
      :class="{'show':monthsShow}"
      class="calendar-months" >
      <span
        v-for="m in monthsSelect"
        :key="m"
        :class="{'active':(m)==month}"
        @click.stop="selectMonth(m)">{{ m+1 }} 月</span>
    </div>

  </div>
</template>

<script>
import calendar from './calendar.js'
export default {
  props: {
    // 多选模式
    multi: {
      type: Boolean,
      default: false
    },
    // 范围模式
    range: {
      type: Boolean,
      default: false
    },
    // 默认日期
    value: {
      type: Array,
      default: function () {
        return []
      }
    },
    // 开始选择日期
    begin: {
      type: Array,
      default: function () {
        return []
      }
    },
    // 结束选择日期
    end: {
      type: Array,
      default: function () {
        return []
      }
    },
    // 日期格式
    formateDate: {
      type: String,
      default: 'yyyy-mm-dd'
    },
    // 是否小于10补零
    zero: {
      type: Boolean,
      default: false
    },
    // 屏蔽的日期
    disabled: {
      type: Array,
      default: function () {
        return []
      }
    },
    // 是否显示农历
    lunar: {
      type: Boolean,
      default: false
    },

    // 自定义星期名称
    weeks: {
      type: Array,
      default: function () {
        return window.navigator.language.toLowerCase() === 'zh-cn'
          ? ['日', '一', '二', '三', '四', '五', '六']
          : ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
      }
    },
    // 自定义月份
    months: {
      type: Array,
      default: function () {
        return window.navigator.language.toLowerCase() === 'zh-cn'
          ? [
            '1',
            '2',
            '3',
            '4',
            '5',
            '6',
            '7',
            '8',
            '9',
            '10',
            '11',
            '12'
          ]
          : [
            'January',
            'February',
            'March',
            'April',
            'May',
            'June',
            'July',
            'August',
            'September',
            'October',
            'November',
            'December'
          ]
      }
    },
    // 自定义事件
    events: {
      type: Object,
      default: function () {
        return {}
      }
    }

  },
  data () {
    return {
      years: [],
      yearsShow: false,
      monthsShow: false,
      year: 0,
      month: 0,
      day: 0,
      monthId: '',
      days: [],
      multiDays: [],
      monthsData: [],
      monthsSelect: [],
      today: [],
      festival: {
        lunar: {
          '1-1': '春节',
          '1-15': '元宵节',
          '2-2': '龙头节',
          '5-5': '端午节',
          '7-7': '七夕节',
          '7-15': '中元节',
          '8-15': '中秋节',
          '9-9': '重阳节',
          '10-1': '寒衣节',
          '10-15': '下元节',
          '12-8': '腊八节',
          '12-23': '祭灶节'
        },
        gregorian: {
          '1-1': '元旦',
          '2-14': '情人节',
          '3-8': '妇女节',
          '3-12': '植树节',
          '4-5': '清明节',
          '5-1': '劳动节',
          '5-4': '青年节',
          '6-1': '儿童节',
          '7-1': '建党节',
          '8-1': '建军节',
          '9-10': '教师节',
          '10-1': '国庆节',
          '12-24': '平安夜',
          '12-25': '圣诞节'
        }
      },
      rangeBegin: [],
      rangeEnd: []
    }
  },
  watch: {
    events () {
      this.render(this.year, this.month)
    },
    value () {
      this.init()
    }
  },
  mounted () {
    this.init()
    this.$nextTick(() => {
      this.tagCurrent()
    })
  },
  methods: {
    init () {
      let now = new Date()
      this.year = now.getFullYear()
      this.month = now.getMonth()
      this.day = now.getDate()
      this.monthId = 'monthId' + (this.month)
      if (this.value.length > 0) {
        if (this.range) {
          // 范围
          this.year = parseInt(this.value[0][0])
          this.month = parseInt(this.value[0][1]) - 1
          this.day = parseInt(this.value[0][2])

          let year2 = parseInt(this.value[1][0])
          let month2 = parseInt(this.value[1][1]) - 1
          let day2 = parseInt(this.value[1][2])

          this.rangeBegin = [this.year, this.month, this.day]
          this.rangeEnd = [year2, month2, day2]
        } else if (this.multi) {
          // 多选
          this.multiDays = this.value
          this.year = parseInt(this.value[0][0])
          this.month = parseInt(this.value[0][1]) - 1
          this.day = parseInt(this.value[0][2])
        } else {
          // 单选
          this.year = parseInt(this.value[0])
          this.month = parseInt(this.value[1]) - 1
          this.day = parseInt(this.value[2])
        }
      }
      for (let i = 0; i < this.months.length; i++) {
        this.render(this.year, i)
      }
    },
    // 渲染日期
    render (y, m) {
      let firstDayOfMonth = new Date(y, m, 1).getDay() // 当月第一天
      let lastDateOfMonth = new Date(y, m + 1, 0).getDate() // 当月最后一天
      // let lastDayOfLastMonth = new Date(y, m, 0).getDate() // 上一月的最后一天
      this.year = y
      let seletSplit = this.value
      let i
      let line = 0
      let temp = []
      let nextMonthPushDays = 1
      for (i = 1; i <= lastDateOfMonth; i++) {
        let day = new Date(y, m, i).getDay() // 返回星期几（0～6）
        // let k
        // 第一行
        if (day === 0) {
          temp[line] = []
        } else if (i === 1) {
          temp[line] = []
          // k = lastDayOfLastMonth - firstDayOfMonth + 1
          for (let j = 0; j < firstDayOfMonth; j++) {
            // console.log("第一行",lunarYear,lunarMonth,lunarValue,lunarInfo)
            temp[line].push(
              { day: '', disabled: true }
            )
            // k++
          }
        }

        if (this.range) {
          // 范围
          // console.log("日期范围",this.getLunarInfo(this.year,this.month+1,i))
          let options = Object.assign(
            { day: i },
            this.getLunarInfo(this.year, m + 1, i),
            this.getEvents(this.year, m + 1, i)
          )
          if (this.rangeBegin.length > 0) {
            let beginTime = Number(
              new Date(
                this.rangeBegin[0],
                this.rangeBegin[1],
                this.rangeBegin[2]
              )
            )
            let endTime = Number(
              new Date(this.rangeEnd[0], this.rangeEnd[1], this.rangeEnd[2])
            )
            let stepTime = Number(new Date(this.year, m + 1, i))
            if (beginTime <= stepTime && endTime >= stepTime) {
              options.selected = true
            }
          }
          if (this.begin.length > 0) {
            let beginTime = Number(
              new Date(
                parseInt(this.begin[0]),
                parseInt(this.begin[1]) - 1,
                parseInt(this.begin[2])
              )
            )
            if (beginTime > Number(new Date(this.year, m + 1, i))) { options.disabled = true }
          }
          if (this.end.length > 0) {
            let endTime = Number(
              new Date(
                parseInt(this.end[0]),
                parseInt(this.end[1]) - 1,
                parseInt(this.end[2])
              )
            )
            if (endTime < Number(new Date(this.year, m + 1, i))) { options.disabled = true }
          }
          if (this.disabled.length > 0) {
            if (
              this.disabled.filter(v => {
                return (
                  this.year === v[0] && m === v[1] - 1 && i === v[2]
                )
              }).length > 0
            ) {
              options.disabled = true
            }
          }
          temp[line].push(options)
        } else if (this.multi) {
          // 多选
          let options
          // 判断是否选中
          if (
            this.value.filter(v => {
              return (
                this.year === v[0] && m === v[1] - 1 && i === v[2]
              )
            }).length > 0
          ) {
            options = Object.assign(
              { day: i, selected: true },
              this.getLunarInfo(this.year, m + 1, i),
              this.getEvents(this.year, m + 1, i)
            )
          } else {
            options = Object.assign(
              { day: i, selected: false },
              this.getLunarInfo(this.year, m + 1, i),
              this.getEvents(this.year, m + 1, i)
            )
            if (this.begin.length > 0) {
              let beginTime = Number(
                new Date(
                  parseInt(this.begin[0]),
                  parseInt(this.begin[1]) - 1,
                  parseInt(this.begin[2])
                )
              )
              if (beginTime > Number(new Date(this.year, m + 1, i))) { options.disabled = true }
            }
            if (this.end.length > 0) {
              let endTime = Number(
                new Date(
                  parseInt(this.end[0]),
                  parseInt(this.end[1]) - 1,
                  parseInt(this.end[2])
                )
              )
              if (endTime < Number(new Date(this.year, m + 1, i))) { options.disabled = true }
            }
            if (this.disabled.length > 0) {
              if (
                this.disabled.filter(v => {
                  return (
                    this.year === v[0] && m === v[1] - 1 && i === v[2]
                  )
                }).length > 0
              ) {
                options.disabled = true
              }
            }
          }

          temp[line].push(options)
        } else {
          // 单选
          // console.log(this.lunar(this.year,m,i));

          let chk = new Date()
          let chkY = chk.getFullYear()
          let chkM = chk.getMonth()
          // 匹配上次选中的日期
          if (
            parseInt(seletSplit[0]) === this.year &&
            parseInt(seletSplit[1]) - 1 === m &&
            parseInt(seletSplit[2]) === i
          ) {
            // console.log("匹配上次选中的日期",lunarYear,lunarMonth,lunarValue,lunarInfo)
            temp[line].push(
              Object.assign(
                { day: i, selected: true },
                this.getLunarInfo(this.year, m + 1, i),
                this.getEvents(this.year, m + 1, i)
              )
            )
            this.today = [line, temp[line].length - 1]
          } else if (
            chkY === this.year &&
            chkM === m &&
            i === this.day &&
            this.value.length === 0
          ) {
            // 没有默认值的时候显示选中今天日期
            // console.log("今天",lunarYear,lunarMonth,lunarValue,lunarInfo)
            temp[line].push(
              Object.assign(
                { day: i, selected: true },
                this.getLunarInfo(this.year, m + 1, i),
                this.getEvents(this.year, m + 1, i)
              )
            )
            this.today = [line, temp[line].length - 1]
          } else {
            // 普通日期
            // console.log("设置可选范围",i,lunarYear,lunarMonth,lunarValue,lunarInfo)
            let options = Object.assign(
              { day: i, selected: false },
              this.getLunarInfo(this.year, m + 1, i),
              this.getEvents(this.year, m + 1, i)
            )
            if (this.begin.length > 0) {
              let beginTime = Number(
                new Date(
                  parseInt(this.begin[0]),
                  parseInt(this.begin[1]) - 1,
                  parseInt(this.begin[2])
                )
              )
              if (beginTime > Number(new Date(this.year, m + 1, i))) { options.disabled = true }
            }
            if (this.end.length > 0) {
              let endTime = Number(
                new Date(
                  parseInt(this.end[0]),
                  parseInt(this.end[1]) - 1,
                  parseInt(this.end[2])
                )
              )
              if (endTime < Number(new Date(this.year, m + 1, i))) { options.disabled = true }
            }
            if (this.disabled.length > 0) {
              if (
                this.disabled.filter(v => {
                  return (
                    this.year === v[0] && m === v[1] - 1 && i === v[2]
                  )
                }).length > 0
              ) {
                options.disabled = true
              }
            }
            temp[line].push(options)
          }
        }
        // 到周六换行
        if (day === 6 && i < lastDateOfMonth) {
          line++
        } else if (i === lastDateOfMonth) {
          // line++
          let k = 1
          for (let d = day; d < 6; d++) {
            // console.log(this.computedNextYear()+"-"+this.computedNextMonth(true)+"-"+k)
            temp[line].push(
              { day: '', disabled: true }
            )
            k++
          }
          // 下个月除了补充的前几天开始的日期
          nextMonthPushDays = k
        }
      } // end for

      // console.log(this.year+"/"+m+"/"+this.day+":"+line)
      // 补充第六行让视觉稳定
      if (line <= 5 && nextMonthPushDays > 0) {
        // console.log({nextMonthPushDays:nextMonthPushDays,line:line})
        for (let i = line + 1; i < 5; i++) {
          temp[i] = []
          let start = nextMonthPushDays + (i - line - 1) * 7
          for (let d = start; d <= start + 6; d++) {
            temp[i].push(
              Object.assign(
                { day: '', disabled: true }
              )
            )
          }
        }
      }

      this.monthsData[m] = temp
    },

    // 获取农历信息
    getLunarInfo (y, m, d) {
      let lunarInfo = calendar.solar2lunar(y, m, d)
      let lunarValue = lunarInfo.IDayCn
      // console.log(lunarInfo)
      let isLunarFestival = false
      let isGregorianFestival = false
      if (
        this.festival.lunar[lunarInfo.lMonth + '-' + lunarInfo.lDay] !==
        undefined
      ) {
        lunarValue = this.festival.lunar[lunarInfo.lMonth + '-' + lunarInfo.lDay]
        isLunarFestival = true
      } else if (this.festival.gregorian[m + '-' + d] !== undefined) {
        lunarValue = this.festival.gregorian[m + '-' + d]
        isGregorianFestival = true
      }

      return {
        lunar: lunarValue,
        isLunarFestival: isLunarFestival,
        isGregorianFestival: isGregorianFestival
      }
    },
    // 获取自定义事件
    getEvents (y, m, d) {
      if (Object.keys(this.events).length === 0) return false
      let eventName = this.events[y + '-' + m + '-' + d]
      let data = {}
      if (eventName !== undefined) {
        data.eventName = eventName
      }
      return data
    },
    // 上月
    prev (e) {
      e.stopPropagation()
      if (this.month === 0) {
        this.month = 11
        this.year = parseInt(this.year) - 1
      } else {
        this.month = parseInt(this.month) - 1
      }
      this.render(this.year, this.month)
      this.$emit('selectMonth', this.month + 1, this.year)
      this.$emit('prev', this.month + 1, this.year)
    },
    //  下月
    next (e) {
      e.stopPropagation()
      if (this.month === 11) {
        this.month = 0
        this.year = parseInt(this.year) + 1
      } else {
        this.month = parseInt(this.month) + 1
      }
      this.render(this.year, this.month)
      this.$emit('selectMonth', this.month + 1, this.year)
      this.$emit('next', this.month + 1, this.year)
    },
    // 选中日期
    select (k1, k2, m, e) {
      if (e !== undefined) e.stopPropagation()
      this.days = this.monthsData[m - 1]
      m = Number(m)
      // 日期范围
      if (this.range) {
        if (this.rangeBegin.length === 0 || this.rangeEndTemp !== 0) {
          this.rangeBegin = [this.year, m, this.days[k1][k2].day]
          this.rangeBeginTemp = this.rangeBegin
          this.rangeEnd = [this.year, m, this.days[k1][k2].day]
          this.rangeEndTemp = 0
        } else {
          this.rangeEnd = [this.year, m, this.days[k1][k2].day]
          this.rangeEndTemp = 1
          // 判断结束日期小于开始日期则自动颠倒过来
          if (
            +new Date(this.rangeEnd[0], this.rangeEnd[1], this.rangeEnd[2]) <
            +new Date(
              this.rangeBegin[0],
              this.rangeBegin[1],
              this.rangeBegin[2]
            )
          ) {
            this.rangeBegin = this.rangeEnd
            this.rangeEnd = this.rangeBeginTemp
          }
          // 小于10左边打补丁
          let begin = []
          let end = []
          if (this.zero) {
            this.rangeBegin.forEach((v, k) => {
              if (k === 1) v = v + 1
              begin.push(this.zeroPad(v))
            })
            this.rangeEnd.forEach((v, k) => {
              if (k === 1) v = v + 1
              end.push(this.zeroPad(v))
            })
          } else {
            begin = this.rangeBegin
            end = this.rangeEnd
          }
          // console.log("选中日期",begin,end)
          if (this.formateDate === 'yyyy-mm-dd') {
            this.$emit('select', begin.join('-'), end.join('-'))
          } else if (this.formateDate === 'yyyy/mm/dd') {
            this.$emit('select', begin.join('/'), end.join('/'))
          } else {
            this.$emit('select', begin, end)
          }
        }
        this.render(this.year, m)
      } else if (this.multi) {
        // 如果已经选过则过滤掉
        let filterDay = this.multiDays.filter(v => {
          return (
            this.year === v[0] &&
            m === v[1] - 1 &&
            this.days[k1][k2].day === v[2]
          )
        })
        if (filterDay.length > 0) {
          this.multiDays = this.multiDays.filter(v => {
            return (
              this.year !== v[0] ||
              m !== v[1] - 1 ||
              this.days[k1][k2].day !== v[2]
            )
          })
        } else {
          this.multiDays.push([
            this.year,
            m + 1,
            this.days[k1][k2].day
          ])
        }
        this.days[k1][k2].selected = !this.days[k1][k2].selected
        this.$emit('select', this.multiDays)
      } else {
        // 取消上次选中
        if (this.today.length > 0) {
          this.days.forEach(v => {
            v.forEach(vv => {
              vv.selected = false
            })
          })
        }
        // 设置当前选中天
        this.days[k1][k2].selected = true
        this.day = this.days[k1][k2].day
        this.today = [k1, k2]
        if (this.formateDate === 'yyyy-mm-dd') {
          this.$emit(
            'select',
            [
              this.year,
              this.zero ? this.zeroPad(m) : m,
              this.zero
                ? this.zeroPad(this.days[k1][k2].day)
                : this.days[k1][k2].day
            ].join('-')
          )
        } else if (this.formateDate === 'yyyy/mm/dd') {
          this.$emit(
            'select',
            [
              this.year,
              this.zero ? this.zeroPad(m) : m,
              this.zero
                ? this.zeroPad(this.days[k1][k2].day)
                : this.days[k1][k2].day
            ].join('/')
          )
        } else {
          this.$emit('select', [
            this.year,
            this.zero ? this.zeroPad(m) : m,
            this.zero
              ? this.zeroPad(this.days[k1][k2].day)
              : this.days[k1][k2].day
          ])
        }
      }
    },
    changeMonth () {
      this.yearsShow = false
      if (this.monthsShow) {
        this.monthsShow = false
        return false
      }
      this.monthsShow = true
      this.monthsSelect = []
      for (let i = 0; i < 12; i++) {
        this.monthsSelect.push(i)
      }
    },
    selectMonth (value) {
      this.monthsShow = false
      this.month = value
      this.monthId = 'monthId' + (this.month)
      this.$nextTick(() => {
        this.tagCurrent()
      })
      this.$emit('selectMonth', value)
    },
    changeYear () {
      this.monthsShow = false
      if (this.yearsShow) {
        this.yearsShow = false
        return false
      }
      this.yearsShow = true
      this.years = []
      let count = 7
      if (this.year === 2017) {
        count = 8
      }
      for (let i = this.year - 1; i < this.year + count; i++) {
        if (i >= 2017) {
          this.years.push(i)
        }
      }
    },
    selectYear (value) {
      let now = new Date()
      let year = now.getFullYear()
      let month = now.getMonth()
      this.yearsShow = false
      if (value > year) {
        value = year
      }
      this.year = value
      for (let i = 0; i < this.months.length; i++) {
        this.render(this.year, i)
      }
      if (year === value) {
        this.monthId = 'monthId' + month
      } else {
        this.monthId = 'monthId0'
      }
      this.$nextTick(() => {
        this.tagCurrent()
      })
      this.$emit('selectYear', value)
    },
    // 返回今天
    setToday () {
      let now = new Date()
      this.year = now.getFullYear()
      this.month = now.getMonth()
      this.day = now.getDate()
      for (let i = 0; i < this.months.length; i++) {
        this.render(this.year, i)
      }
      // 遍历当前日找到选中
      this.monthId = 'monthId' + (this.month)
      this.days = this.monthsData[this.month]
      this.days.forEach(v => {
        let day = v.find(vv => {
          return vv.day === this.day && !vv.disabled
        })
        if (day !== undefined) {
          day.selected = true
        }
      })
    },
    // 日期补零
    zeroPad (n) {
      return String(n < 10 ? '0' + n : n)
    },
    tagCurrent () {
      document.getElementById(this.monthId).scrollIntoView()
    }
  }
}
</script>

<style scoped lang="scss">
$font_color:#ffffff;
$f-size: .26rem;
$bg_active:#3C8ACC;
$bg_color:#2F3C86;
$other_color:#FF9800;
.calendar {
  margin: auto;
  margin-top:1rem;
  width: 95%;
  height: 85%;

  min-width: 3.00rem;
  background:#251F5B;
  font-family: "PingFang SC", "Hiragino Sans GB", "STHeiti", "Microsoft YaHei",
    "WenQuanYi Micro Hei", sans-serif;
  user-select: none;
}

.calendar-tools {
  height: .90rem;
  font-size: $f-size;
  line-height: .40rem;
  color:$font_color;
}
.calendar-tools span {
  cursor: pointer;
}
.calendar-prev {
  width: 14.28571429%;
  float: left;
  text-align: center;
}

.calendar-month{
  display: block;
  width:100%;
  height:100%;
  padding-bottom: 11rem;
  overflow: hidden;
  overflow-y: auto;
  div.year {
    font-size: .26rem;
    height:.8rem;
    color: $font_color;
    text-align: center;
    padding: 0 1.5rem;
    i{
      display: inline-block;
      width:1rem;
      height:.6rem;
      font-size: .26rem;
      color: #65C4EA;
      text-align: center;
      position: relative;

      .down {
        position: absolute;
        right:-10%;
        top:50%;
        display: inline-block;
        height:0;
        width:0;
        border-top:.1rem solid #ffffff;
        border-bottom:.1rem solid transparent;
        border-left:.1rem solid transparent;
        border-right:.1rem solid transparent;
      }
      &.aiction{
        border-bottom: #ffffff solid .01rem;
        color: #ffffff;
      }
    }
  }
}
.calendar-next {
  width: 14.28571429%;
  float: right;
  text-align: center;
  color:$font_color;
}
.table-box {
  border: rgba(60, 138, 204, .38) solid .01rem;
  padding: 0.1rem .2rem .3rem .2rem;
  background: rgba(47, 60, 134, .38);
}
.calendar table {
  clear: both;
  width: 100%;
  padding-top: .2rem;
  margin-bottom: .10rem;
  border-collapse: collapse;
  color:$font_color;

}
.calendar tbody {
  border: rgba(60, 138, 204, .38) solid .01rem;
  margin: .05rem;
  background: rgba(47, 60, 134, .38);
}
.calendar td {
  margin: .2rem !important;
  padding: 0rem 0;
  width: 14.28571429%;
  height: .44rem;
  text-align: center;
  vertical-align: middle;
  font-size: $f-size;
  line-height: 125%;
  cursor: pointer;
  position: relative;
  vertical-align: top;
}
.calendar td.week {
  font-size: $f-size;
  padding:.2rem 0;
  pointer-events: none !important;
  cursor: default !important;
}
.calendar td.disabled {
  color: #ccc;
  pointer-events: none !important;
  cursor: default !important;
}
.calendar td.disabled div {
  color: #ccc;
}
.calendar td span {
  display: block;
  max-width: .80rem;
  height: 1rem;
  font-size: $f-size;
  line-height: .5rem;
  margin: 0rem auto;
  border-radius: .10rem;
}
.calendar td:not(.selected) span:not(.red):hover {
  background: #092053;
  color: #444;
}
.calendar td:not(.selected) span.red:hover {
  background: #f9efef;
}

.calendar td:not(.disabled) span.red {
  color: $other_color;
}
.calendar td.selected span {
  background-color: $bg_active;
  color:$font_color;
}
.calendar td .text {
  position: absolute;
  top: 0rem;
  left: 0;
  right: 0;
  text-align: center;

  padding: .4rem 0.01rem;
  font-size: .26rem;
  line-height: 0.4rem;
  color:$font_color;
}
.calendar td .isGregorianFestival,
.calendar td .isLunarFestival {
  color: $other_color;
}
.calendar td.selected span.red {
  background-color: $other_color;
  color:$font_color;
}
.calendar td.selected span.red:hover {
  background-color: $other_color;
  color:$font_color;
}
.calendar thead td {
  text-transform: uppercase;
  height: .30rem;
  vertical-align: middle;
}
.calendar-button {
  text-align: center;
}
.calendar-button span {
  cursor: pointer;
  display: inline-block;
  min-height: .1em;
  min-width: .5rem;
  vertical-align: baseline;
  background: linear-gradient(#092053, #06050c);
  color: #fff;
  margin: 0 0.25rem 0 0;
  padding: 0.6rem .2rem;
  font-size: $f-size;
  line-height: 1rem;
  text-align: center;
  border-radius: 0.3rem;
}
.calendar-button span.cancel {
  background: #efefef;
  color: #666;
}
.calendar-years {
  position: absolute;
  left: 0rem;
  top: 2.2rem;
  right: 0rem;
  bottom: 0rem;
  background: #3C8ACC;
  margin: 0 .2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  overflow: auto;
  transition: all 0.5s cubic-bezier(0.075, 0.82, 0.165, 1);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-.10rem);
}
.calendar-years.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0rem);
  height:2rem;
}
.calendar-years > span {
  margin: .01rem .05rem;
  display: inline-block;
  width: 1.5rem;
  line-height: .6rem;
  border-radius: .10rem;
  text-align: center;
  border: 1px solid $font_color;
  color:$font_color;
}
.calendar-years > span.active {
  border: 1px solid $bg_active;
  background-color: #E6933C;
  color:$font_color;
}
.calendar-months {
  position: absolute;
  left: 0rem;
  top: 2.3rem;
  right: 0rem;
  bottom: 0rem;
  margin: 0 .2rem;
  background: #3C8ACC;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  overflow: auto;
  transition: all 0.5s cubic-bezier(0.075, 0.82, 0.165, 1);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-.10rem);
}
.calendar-months.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0rem);
  height:3rem;
}
.calendar-months > span {
  margin: .01rem .05rem;
  display: inline-block;
  width: 1.5rem;
  line-height: .6rem;
  border-radius: .20rem;
  text-align: center;
  border: 1px solid $font_color;
  color:$font_color;
}
.calendar-months > span.active {
  border: 1px solid $bg_active;
  background-color: #E6933C;
  color:$font_color;
}
</style>
